﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ppt = Microsoft.Office.Interop.PowerPoint;

namespace ObjectModel.PowerPoint
{
    /// <summary>
    /// A class that updates the state of a dictionary of LinkedObjectCollections in
    /// response to PowerPoint events.
    /// </summary>
    public class LinkedObjectsBySlideController
    {
        readonly LinkedObjectsBySlide mLinkedObjectsBySlide;
        readonly PresentationEvents mEvents;
        readonly SlideKeyDictionaryController<LinkedObjectCollection> mController;
        
        public LinkedObjectsBySlideController(LinkedObjectsBySlide linkedObjectsBySlide, Ppt.Presentation pres)
        {
            mController = new SlideKeyDictionaryController<LinkedObjectCollection>(mLinkedObjectsBySlide, pres);
            
            mLinkedObjectsBySlide = linkedObjectsBySlide;
            mEvents = Globals.PresentationEvents[pres];
            mEvents.SlideActivated += OnSlideActivated;
        }

        void OnSlideActivated(object sender, SlideChangedEventArgs e)
        {
            mLinkedObjectsBySlide.ActiveCollection = mLinkedObjectsBySlide[e.SlideInfo.Id];
        }
    }
}
